package com.Set集合.不重复的随机数;

import java.util.HashSet;
import java.util.Random;
/*
1到20之间不重复的随机数
 */
public class Demo {
    public static void main(String[] args) {
        HashSet<Integer> hashSet = new HashSet<>();
        Random random = new Random();

        while (hashSet.size()<10){
            int i = random.nextInt(20)+1;
            hashSet.add(i);
        }

        for (Integer integer : hashSet) {
            System.out.println(integer);
        }

    }
}
